package com.lh.item.service.impl;

import com.lh.item.mapper.CategoryMapper;
import com.lh.item.pojo.CategoryDo;
import com.lh.item.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuhe
 * @date 2020/06/17
 */
@Service
public class CategoryServiceImpl implements ICategoryService {

    private final CategoryMapper categoryMapper;

    @Autowired
    public CategoryServiceImpl(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    @Override
    public List<CategoryDo> queryCategoriesByPid(Long pid) {
        CategoryDo record = new CategoryDo();
        record.setParentId(pid);
        return this.categoryMapper.select(record);
    }

    @Override
    public List<String> queryNamesByIds(List<Long> ids) {
        List<CategoryDo> categories = this.categoryMapper.selectByIdList(ids);
        ArrayList<String> names = new ArrayList<>();
        categories.forEach(categoryDo -> {
            names.add(categoryDo.getName());
        });
        return names;
    }

}
